{% extends 'base.html' %}
{% block css %}

{% endblock %}
{% block title %}
    编辑用户权限
{% endblock %}
{% block page-title %}
    编辑用户权限
{% endblock %}
{% block page-content %}
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">编辑<strong>{{ object.last_name }}{{ object.first_name }}</strong>的用户权限</h3>
                </div>
                <div class="panel-body">
                    {% if messages %}
                        {% for message in messages %}
                            <div class="alert alert-{{ message.tags }} alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                {{ message }}
                            </div>
                        {% endfor %}
                    {% endif %}
                    <form action="" method="post" style="overflow: hidden">
                        <!-- https://www.cnblogs.com/sly27/p/10515853.html -->
                        {% regroup permissions by content_type__app_label as perm_list %}
                        {% for permission in perm_list %}
                            <div style="margin-bottom: 5px;overflow: hidden">
                                <h4>
                                    {% if permission.grouper == 'auth' %}认证与授权
                                    {% elif permission.grouper == 'users' %}用户管理
                                    {% elif permission.grouper == 'cmdb' %}CMDB
                                    {% elif permission.grouper == 'task' %}任务系统
                                    {% else %} {{ permission.grouper }}
                                    {% endif %}
                                 </h4>

                                <div class="col-sm-12" style="padding-left: 0">
                                    {% for perm in permission.list %}
                                        <label class="checkbox-inline" style="margin-bottom: 10px">
                                            <input type="checkbox" name="user_permissions"
                                                   value="{{ perm.id }}"
                                                   {% for permission in object.user_permissions.all %}{% ifequal permission.id perm.id %}checked
                                                   {% endifequal %}{% endfor %}> {{ perm.name }}
                                        </label>
                                    {% endfor %}
                                </div>
                            </div>
                        {% endfor %}
                        <div class="form-group">
                            <div class="col-sm-4" style="padding-left: 0">
                                <input class="btn btn-primary" type="submit" name="_save" value="保存">
                                <input class="btn btn-primary" type="submit" name="_addanother" value="保存并继续编辑">
                                <input class="btn btn-white" type="reset" value="取消">
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        $('.user').addClass('active');
        $('.user .users').addClass('active');
    </script>
{% endblock %}